Skip to content

Conversation

@mokagio
Copy link
Contributor

@mokagio mokagio commented Apr 19, 2023

Because of the Swift Package manager support defined in #68 and fixed in #76 we no longer need to use CocoaPods to integrate the local framework in the demo app. This PR removes CocoaPods and updates the folder structure to the standard SPM setup, with Sources/ and Tests/. The demo app now lives in Demo/.

Moving around the project had the side effect of changing the test host path for the unit tests and that revealed a unit tests failure in testGlobalPause(). I had been investigating that since yesterday, but only today found the fix: the test needs to call the configure(testId:) method on the shared instance. I haven't dug into the reason for this, but I seems like a useful rabbit hole to go down into.

After noticing the test host path change, I decided to update the tests to run without a test host. I find this usually results in a leaner tests execution and removes the chance of state from the demo app leaking in the tests.

As a result of having the local package, I was also able to remove the ParselyTracker development framework. That means that now the demo app and the tests refer to the local Package making the test setup closer to the way our users would integrate the app. (An alternative would be to use CocoaPods to integrate, but with pod 'ParselyAnalytics', path: '.')


I'm leaving this as a draft for now on top of the branch mokagio/merge-resolution-76-reference as I'm waiting for input by @cwisecarver on merge resolution question in #76. Ready to review.

mokagio added 11 commits April 19, 2023 12:50
This source filed did not need to be compiled in those targets.
We were no longer importing any dependency via the `Podfile`
This is to be inline with the standard Swift Package setup
This is to be inline with the standard Swift Package setup
Notice all the `import ParselyTracker` are now `import
ParselyAnalytics`, which is consistent with what our users would be
doing.
I think the reason the tests started to fail with this setup is that the
path to the host app for the unit tests changed and that, for some
reason still unknown to me, seem to clash with the configure call
execution.
Notice this also required updating the test for the generated user agent
because the generation logic uses the app name.
Comment on lines +16 to +19
s.test_spec 'Tests' do |test_spec|
test_spec.source_files = 'Tests'
test_spec.dependency 'Nimble'
end
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is neat. It will make the unit tests run as part of the pod validation process.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can change the "Build and Test" CI task to run tests using SPM (via xcodebuild test) and CocoaPods (via pod lint)?

// be in the format
//
// xctest/<Xcode version> iOS/<iOS version> (<architecture>)
expect(RequestBuilder.getUserAgent()).to(match("xctest\\/\\d+\\.\\d+ iOS\\/\\d+\\.\\d+ (.*)"))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotta love Nimble for offering a RegEx matcher

@mokagio mokagio added this to the 0.2.2 milestone Apr 19, 2023

func testGlobalPause() {
// This is call to configure required for the start-stop mechanism to work
sharedInstance?.configure(siteId: ParselyTestCase.testApikey)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think changing this test case to use ParselyTestCase.parselyTestTracker instead of the singleton? You'll still need to call this configure function, but at least there is no potential side effect to other test cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I used sharedInstance because that's the object the tests run assertions again, but that doesn't mean we cannot rewrite the test to use the test-scoped value.

I got carried away and did a bunch of refactoring around it in #78, which is on top of this PR.

@mokagio mokagio marked this pull request as ready for review April 20, 2023 00:01
@mokagio mokagio requested a review from crazytonyli April 20, 2023 05:54
@crazytonyli crazytonyli changed the base branch from mokagio/merge-resolution-76-reference to master April 20, 2023 07:44
@crazytonyli
Copy link
Contributor

@mokagio I took the liberty to change the base branch, because the original one mokagio/merge-resolution-76-reference doesn't have new commits on top of the master branch. Also, we can get PR checks when targeting the master branch.

Copy link
Contributor

@crazytonyli crazytonyli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

This AnalyticsSDKTests seems can be removed.

Copy link
Contributor

@cwisecarver cwisecarver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes all look good to me. Lots of good cleanup work. I am getting sporadic test failures on these two tests. It's not every time and I've never had them both fail but they each seem to fail about every third test run. Seems unlikely that it's related to this PR but I wanted to raise it.

Screenshot 2023-04-20 at 3 33 56 PM

Screenshot 2023-04-20 at 3 33 13 PM

@crazytonyli crazytonyli reopened this Apr 23, 2023
@crazytonyli
Copy link
Contributor

⬆️ I reopened this PR to trigger the GitHub Action

@crazytonyli crazytonyli merged commit 57a50fb into master Apr 23, 2023
@mokagio mokagio deleted the mokagio/spm-tests branch April 25, 2023 10:26
mokagio added a commit that referenced this pull request Apr 25, 2023
mokagio added a commit that referenced this pull request Apr 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants